package com.spring.iosservice.web.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONException;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PartETag;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.google.common.collect.Maps;
import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spera.aliyunContent.AliyunContent;
import com.spera.aliyunUtil.CreateOSSClient;
import com.spera.aliyunUtil.SperaOSSUtil;
import com.spera.aliyunUtil.SperaPartETag;
import com.spera.genutil.Token;
import com.spera.genutil.tools;
import com.spera.shopoa.util.ShopOaSessionUtil;
import com.spring.comment.web.service.CommentService;
import com.spring.common.web.service.CommonService;
import com.spring.iosservice.web.model.BabyCourseVideo;
import com.spring.iosservice.web.model.CheckUser;
import com.spring.iosservice.web.model.CourseBooks;
import com.spring.iosservice.web.model.CourseImage;
import com.spring.iosservice.web.model.CourseMtsInfo;
import com.spring.iosservice.web.model.OssPartInfo;
import com.spring.iosservice.web.model.StudenetAndComment;
import com.spring.iosservice.web.model.StudentList;
import com.spring.iosservice.web.model.TeacherCourse;
import com.spring.iosservice.web.model.TeacherVideo;
import com.spring.iosservice.web.service.IosQuestService;
import com.spring.security.core.feature.cache.redis.CopyFile;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.core.util.UDate;
import com.spring.security.filestream.config.Configurations;
import com.spring.security.filestream.servlet.Range;
import com.spring.security.filestream.servlet.StreamException;
import com.spring.security.filestream.util.IoUtil;
import com.spring.security.filestream.util.ReadFromFile;
import com.spring.security.filestream.util.TokenUtil;
import com.spring.security.web.dao.JedisCache;

/**
 * Created by wojunyu on 2015/7/26.
 */
@Controller
@RequestMapping(value = "/iosQuest")
@ApiIgnore
public class IosQuestController {
	static Logger logger = Logger.getLogger(IosQuestController.class.getName());

	@Resource
	private IosQuestService iosQuestService;
	@Resource
	private CommentService commentService;	
	@Resource
	private MongoTemplate mongoService;
	@Resource
	private CommonService commonService;

	
	// 根据教师名生成某日课程列表
	@RequestMapping(value = "/getTeacherCourse")
	@ResponseBody
	public Object getTeacherCourse(String t_user_id, String course_time,
			String course_time_end, String state, String callback,
			String token, String get_has_video,String businessTypeCode,String productCode) {

//		Map<String, Object> t = checkToken(token);
//		if (t != null) {
//			if (ApplicationUtils.isNotNull(callback)) {
//				return new JSONPObject(callback, t);
//			} else {
//				return t;
//			}
//		}

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			List<TeacherCourse> questList = iosQuestService.getTeacherCousre(
					t_user_id, course_time, course_time_end, state,
					get_has_video,businessTypeCode,productCode);

			m.put(ApplicationUtils.DATASET, questList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "取数成功");

		} catch (Exception e) {
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}

	}

	

		    @RequestMapping(value = "/getTeacherCareClass")
		    @ResponseBody
		    public Object getTeacherCareClass(String t_user_id, String productCode,
					String begin_time, String end_time, String state, String token,String callback) throws Exception{
		    	System.out.println(t_user_id+","+productCode+","+begin_time+","+end_time+","+state+","+token);
		    	Map<String,Object> rt = Maps.newHashMap();
		    	try{
		    		rt = iosQuestService.getTeacherCareClass(t_user_id, productCode, begin_time, end_time, state, token);
		    	}catch(Exception e){
		    		rt.put(ApplicationUtils.STATUS, "0");
		    		rt.put(ApplicationUtils.MSG, "系统异常");
		    		e.printStackTrace();
		    	}
		        if(ApplicationUtils.isNotNull(callback)){
		        	return new JSONPObject(callback, rt);
		        }else{
		        	return rt;
		        }
		    }		
		    
		    
		    @RequestMapping(value = "/getTeacherAllCourse")
		    @ResponseBody
		    public Object getTeacherAllCourse(String t_user_id, String productCode,
					String begin_time, String end_time, String state, String token,String callback) throws Exception{
		    	Map<String,Object> rt = Maps.newHashMap();
		    	try{
		    		
		    		rt = iosQuestService.getTeacherAllCourse(t_user_id, productCode, begin_time, end_time, state, token);
		    		
		    	}catch(Exception e){
		    		rt.put(ApplicationUtils.STATUS, "0");
		    		rt.put(ApplicationUtils.MSG, "系统异常");
		    		e.printStackTrace();
		    	}
		        if(ApplicationUtils.isNotNull(callback)){
		        	return new JSONPObject(callback, rt);
		        }else{
		        	return rt;
		        }
		    }
			
	/**
	 * 获取学生 课程或商品
	 * @param course_open_detail_id
	 * @param productId 商品编号  查询该商品下当前登记的小孩
	 * @param unSignOff 是否签退  1为正在上课且未签退的学生，0为已签到未入场的学生 2为已签退的学生  不传为所有的学生
	 * @param callback
	 * @param token
	 * @return
	 */
	@RequestMapping(value = "/getStudenetList")
	@ResponseBody
	public Object getStudenetList(String course_open_detail_id,
			String care_class_openId,
			String productId,
			String unSignOff, 
			String callback,
			String classId,
			String token) {

		Map<String, Object> t = checkToken(token);
		if (t != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, t);
			} else {
				return t;
			}
		}

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			List<StudentList> questList = null;
			if(StringUtils.isNotBlank(course_open_detail_id)){
				questList = iosQuestService.getStudenetList(course_open_detail_id,unSignOff);
			}else if(StringUtils.isNotBlank(care_class_openId)){
				questList = iosQuestService.getCareStudenetList(care_class_openId,unSignOff);
			}else if(StringUtils.isNotBlank(productId)){
				questList = iosQuestService.getProStudenetList(productId,unSignOff);
			}else if(StringUtils.isNotBlank(classId)){
				questList = iosQuestService.getStudenetListByClassID(classId,unSignOff);
			}

			m.put(ApplicationUtils.DATASET, questList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "取数成功");

		} catch (Exception e) {
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	
	
	
	// 所有学员名单和评论
	@RequestMapping(value = "/getStudenetAndCommentList")
	@ResponseBody
	public Object getStudenetAndCommentList(String course_open_detail_id, String callback,
			String token) {

//		Map<String, Object> t = checkToken(token);
//		if (t != null) {
//			if (ApplicationUtils.isNotNull(callback)) {
//				return new JSONPObject(callback, t);
//			} else {
//				return t;
//			}
//		}

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			
			
			List<StudenetAndComment> questList = iosQuestService
					.getStudenetAndCommentList(course_open_detail_id);
			m.put(ApplicationUtils.DATASET, questList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "取数成功");

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println(m.size());

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	@RequestMapping(value = "/getCourseBooks")
	@ResponseBody
	public Object getCourseBooks(String course_id, String callback, String token) {
		
		Map<String, Object> t = checkToken(token);
		if (t != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, t);
			} else {
				return t;
			}
		}

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			List<CourseBooks> questList = iosQuestService
					.getCousreBooks(course_id);
			m.put(ApplicationUtils.DATASET, questList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "取数成功");

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println(m.size());

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	// 根据具体的开课id获得视频列表
	@RequestMapping(value = "/getBabyCourseSpec")
	@ResponseBody
	public Object getBabyCourseSpec(String t_user_id, String baby_id,
			String course_open_detail_id, String callback, String token) {

		Map<String, Object> t = checkToken(token);
		if (t != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, t);
			} else {
				return t;
			}
		}
		
		Map<String, Object> m = new HashMap<String, Object>();
		
		if(!ApplicationUtils.isNotNull(t_user_id)||!ApplicationUtils.isNotNull(course_open_detail_id)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "缺少参数，取数失败");
			return m;
		}

		try {
			List<BabyCourseVideo> questList = iosQuestService.getBabyCourseSpec(
					t_user_id, baby_id, course_open_detail_id);
			m.put(ApplicationUtils.DATASET, questList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "取数成功");

		} catch (Exception e) {
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	// 根据视频id获取视频详细信息
	@RequestMapping(value = "/getTeacherVideo")
	@ResponseBody
	public Object getTeacherVideo(String course_video_id, String callback,
			String token) {

		Map<String, Object> t = checkToken(token);
		if (t != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, t);
			} else {
				return t;
			}
		}

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			List<TeacherVideo> questList = iosQuestService
					.getTeacherVideo(course_video_id);
			m.put(ApplicationUtils.DATASET, questList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "取数成功");

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println(m.size());

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	// 根据图片id获取图片详细信息
	@RequestMapping(value = "/getCourseImage")
	@ResponseBody
	public Object getCourseImage(String course_image_id, String callback,
			String token) {

		Map<String, Object> t = checkToken(token);
		if (t != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, t);
			} else {
				return t;
			}
		}

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			List<CourseImage> questList = iosQuestService
					.getCourseImage(course_image_id);
			m.put(ApplicationUtils.DATASET, questList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "取数成功");

		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println(m.size());

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	// 评语上传
	@RequestMapping(value = "/commitComments")
	@ResponseBody
	public Object commitComments(String t_user_id, String course_videos_id,
			String course_baby_comment, String callback, String token) {
		Map<String, Object> t = checkToken(token);
		if (t != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, t);
			} else {
				return t;
			}
		}
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			iosQuestService.commitComments(t_user_id, course_videos_id,
					course_baby_comment);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "插入成功");
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	@RequestMapping(value = "/commitCourseImageComments")
	@ResponseBody
	public Object commitCourseImageComments(String user_id,String user_type,String user_name,
			String course_image_id,
			String course_baby_comment, String callback, String token) {
		Map<String, Object> t = checkToken(token);
		if (t != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, t);
			} else {
				return t;
			}
		}
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			m=iosQuestService.commitCourseImageComments(user_id,user_type,user_name,course_image_id,
					course_baby_comment);
//			m.put(ApplicationUtils.STATUS, "1");
//			m.put(ApplicationUtils.MSG, "插入成功");
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
			
			
		}
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	@Resource
	private JedisCache jedisCache;

	// IOS登陆接口
	@RequestMapping(value = "/checkUser"/* ,method = RequestMethod.GET */)
	@ResponseBody
	public Object checkUser(String username, String password, String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
//			System.out.println(username);
			
			Map<String,Object> retObj = ShopOaSessionUtil.checkOaUser(username, password);
//			System.out.println("------>"+ApplicationUtils.Object2String(retObj.get("error")));
			if(ApplicationUtils.isNotNull(ApplicationUtils.Object2String(retObj.get("error")))){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "登录失败");
			} else {
				String t_user_id = ApplicationUtils.Object2String(retObj.get("LOGIN_USER_ID"));
				if(StringUtils.isBlank(t_user_id)){
					m.put(ApplicationUtils.MSG, "登录失败");
					m.put(ApplicationUtils.STATUS, "0");
					return m;
				}
				
				CheckUser user = new CheckUser();
				List<CheckUser> checkUser = iosQuestService.checkUser(t_user_id);
				if(checkUser!=null&&checkUser.size()>0){
					user = (CheckUser) checkUser.get(0);
				}else{
					user.setUser_id(t_user_id);
				}
				user.setTeacher_name(ApplicationUtils.Object2String(retObj.get("LOGIN_USER_NAME")));
				String kids_parkId = "";
				//查询绑定关系
				if(ApplicationUtils.isNotNull(ApplicationUtils.Object2String(retObj.get("SHOP_DEPT_ID")))){
					String kids_park_id = commonService.getKidParkIDByDeptID(ApplicationUtils.Object2String(retObj.get("SHOP_DEPT_ID")));
					if(ApplicationUtils.isNotNull(kids_park_id)){
						kids_parkId = kids_park_id;
					}else{
						m.put(ApplicationUtils.MSG, "登录失败，用户未设定所属门店绑定关系");
						m.put(ApplicationUtils.STATUS, "0");
						return m;
					}
				}else{
					m.put(ApplicationUtils.MSG, "登录失败，用户未设定所属门店");
					m.put(ApplicationUtils.STATUS, "0");
					return m;
				}
				
				Token tsession = new Token();
				tsession.setUser_id(user.getUser_id()).setUser_name(user.getTeacher_name()).setKids_park_id(kids_parkId);				
				
				String user_uuid = com.spera.genutil.TokenUtil.SetSperaToken(jedisCache, tsession,60 * 60 * 24,
						com.spera.genutil.TokenUtil.OA_LOGIN);
				
//				user.setImage_src(properties.photeRoot + user.getImage_src());
//				String user_uuid = ApplicationUtils.randomUUID() + "_"
//						+ UDate.dateToStr(new Date(), "yyyyMMddHHmmss")
//						+ user.getUser_id();
//				jedisCache.setEx(user_uuid, 60 * 60 * 24, user.getUser_id());
//				jedisCache.rpush(user_uuid,user.getUser_id());
//				jedisCache.rpush(user_uuid,user.getTeacher_name());
//				jedisCache.expire(user_uuid, 60 * 60 * 24);
//				System.out.println("checkUser");
				
				user.setToken(user_uuid);
				List<CheckUser> dataSet = new ArrayList<CheckUser>();
				dataSet.add(user);
				m.put(ApplicationUtils.DATASET, dataSet);
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "登录成功");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	// 断点上传获取token
	@RequestMapping(value = "/uploadtk_Lo", method = RequestMethod.GET)
	@ResponseBody
	public Object uploadtk_Lo(HttpServletRequest req, HttpServletResponse resp,
			String file_name, String file_size) throws ServletException,
			IOException {
		String token = TokenUtil.generateToken(file_name, file_size);
		Map<String, Object> jsonStr = new HashMap<String, Object>();
		jsonStr.put("token", token);
		int hasin = iosQuestService.checkFileToken(jsonStr);
		if (hasin != 0) {
			jsonStr.put(ApplicationUtils.STATUS, "2");
			jsonStr.put(ApplicationUtils.MSG, "附件已存在");
			return jsonStr;
		}

		try {

			if (Configurations.isCrossed())
				jsonStr.put("server", Configurations.getCrossServer());
			jsonStr.put(ApplicationUtils.STATUS, "1");
			jsonStr.put(ApplicationUtils.MSG, "成功");
		} catch (JSONException e) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "失败");
		}
		System.out.println("TokenServlet---->doGet--->json:" + jsonStr);
		return jsonStr;
	}

	// 断点上传获取pos
	@RequestMapping(value = "/uploadpos_Lo", method = RequestMethod.GET)
	@ResponseBody
	public Object uploadpos_Lo(HttpServletRequest req, HttpServletResponse resp,
			String token, String file_name, String file_size)
			throws ServletException, IOException {
		doOptions(req, resp);

		Map<String, Object> jsonStr = new HashMap<String, Object>();
		long start = 0;
		boolean success = true;
		String message = "success";
		try {
			File f = IoUtil.getTokenedFile(token);
			start = f.length();
			if (token.endsWith("_0") && "0".equals(file_size) && 0 == start)
				f.renameTo(IoUtil.getFile(file_name));
		} catch (FileNotFoundException fne) {
			message = "Error: " + fne.getMessage();
			success = false;
		} finally {
			try {
				if (success)
					jsonStr.put("start", start);
				jsonStr.put(ApplicationUtils.STATUS, "1");
				jsonStr.put(ApplicationUtils.MSG, message);
			} catch (JSONException e) {
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, message);
			}
			System.out.println("uploadpos---->doGet--->json:" + jsonStr);
		}
		return jsonStr;
	}

	// 断点上传
	@RequestMapping(value = "/upload_Lo", method = RequestMethod.POST)
	@ResponseBody
	public Object upload_Lo(HttpServletRequest req, HttpServletResponse resp,
			String token, String file_name,
			@RequestParam(value = "mp4", required = false) MultipartFile mp4,
			String course_open_detail_id, String c_baby_id)
			throws ServletException, IOException {
		Map<String, Object> jsonStr = new HashMap<String, Object>();

		if (!ApplicationUtils.isNotNull(course_open_detail_id)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "请先选择课程");
			return jsonStr;
		}

		if (!ApplicationUtils.isNotNull(c_baby_id)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "请先选择学生");
			return jsonStr;
		}

		doOptions(req, resp);
		// 请求的参数有根据生成的token、文件的名字
		Range range = IoUtil.parseRange(req);

		OutputStream out = null;
		InputStream content = null;
		long start = 0;
		boolean success = true;
		String message = "success";
		File f = IoUtil.getTokenedFile(token);
		try {
			if (f.length() != range.getFrom()) {
				throw new StreamException(
						StreamException.ERROR_FILE_RANGE_START);
			}

			out = new FileOutputStream(f, true);
			content = req.getInputStream();

			byte[] bytes = mp4.getBytes();

			out.write(bytes);

			start = f.length();
		} catch (StreamException se) {
			success = StreamException.ERROR_FILE_RANGE_START == se.getCode();
			message = "Code: " + se.getCode();
		} catch (FileNotFoundException fne) {
			message = "Code: " + StreamException.ERROR_FILE_NOT_EXIST;
			success = false;
		} catch (IOException io) {
			message = "IO Error: " + io.getMessage();
			success = false;
		} finally {
			IoUtil.close(out);
			IoUtil.close(content);

			if (range.getSize() == start) {// 传递完毕
				File dst = IoUtil.getFile(file_name);
				dst.delete();
				f.renameTo(dst);
				System.out.println("传输完毕--->TK: `" + token + "`, NE: `"
						+ file_name + "`");
				if (Configurations.isDeleteFinished()) {// 传输完毕，保存数据
					dst.delete();
				}
				String src = Configurations.getFileRepository()
						+ File.separator + file_name;

				// /upload/video_upload/
				String newFile = "upload" + File.separator + "video_upload"
						+ File.separator;

				String uploadPath = req.getSession().getServletContext()
						.getRealPath(newFile);
				if (!new File(uploadPath).isDirectory()) {
					new File(uploadPath).mkdirs();
				}
				String filename = ApplicationUtils.randomUUID() + "_"
						+ file_name;
				uploadPath += File.separator + filename;
				CopyFile cp = new CopyFile();
				cp.moveFile(src, uploadPath);
				String course_videos_id = ApplicationUtils.randomUUID();
				Map<String, Object> s = new HashMap<String, Object>();
				s.put("id", course_videos_id);
				s.put("c_baby_ids", c_baby_id);
				s.put("course_open_detail_id", course_open_detail_id);
				s.put("course_videos_id", course_videos_id);
				s.put("video_src", "/upload/video_upload/" + filename);
				s.put("video_name", file_name);
				iosQuestService.insertVideos(s);
				// String photoSrc =
				// iosQuestService.queryVideosPhoto(course_videos_id);
				jsonStr.put("course_videos_id", course_videos_id);

			}
			try {
				if (success)
					jsonStr.put("start", start);
				jsonStr.put(ApplicationUtils.STATUS, "1");
				jsonStr.put(ApplicationUtils.MSG, message);
			} catch (JSONException e) {
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, message);
			}
			System.out.println("upload---->dopost--->json:" + jsonStr);
		}
		return jsonStr;
	}

	/**
	 * 视频封面更新
	 * 
	 * @param req
	 * @param resp
	 * @param course_videos_id
	 * @param photo
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping(value = "/updateVideosPhoto", method = RequestMethod.POST)
	@ResponseBody
	public Object updateVideosPhoto(HttpServletRequest req,
			HttpServletResponse resp, String course_videos_id,
			@RequestParam(value = "photo", required = false) MultipartFile photo)
			throws ServletException, IOException {
		System.out.println("sessionid:" + req.getSession().getId());
		Map<String, Object> ret = new HashMap<String, Object>();
		if (!ApplicationUtils.isNotNull(course_videos_id)) {
			ret.put(ApplicationUtils.STATUS, "0");
			ret.put(ApplicationUtils.MSG, "请先选择视频");
			return ret;
		}
		Map<String, Object> s = new HashMap<String, Object>();
		s.put("id", course_videos_id);
		try {
			if (!photo.isEmpty()) {
				String fileName = photo.getOriginalFilename();
//				Date d = new Date();
				
				Integer fileSize = Integer.valueOf(0);
//				File filePath = null;
//				byte[] bytes = photo.getBytes();
				fileSize = Integer.valueOf((int) photo.getSize() / 1024);
				if (fileSize.intValue() <= 102400) {
					
					String newfilename = "vp_"
							+ ApplicationUtils.randomUUID() + "_" + fileName;
					
					String filePath = SperaOSSUtil.springFileUpOss(AliyunContent.fileBucket,"courseVideo_image/"+UDate.getDate()+"/"+newfilename, photo);
					// upload/video_photo_image/
//					String uploadStr = "upload" + File.separator
//							+ "video_photo_image" + File.separator;
//
//					String uploadPath = req.getSession().getServletContext()
//							.getRealPath(uploadStr);
//
//					if (!(new File(uploadPath).isDirectory())) {
//						new File(uploadPath).mkdirs();
//					}
//					uploadPath += File.separator + newfilename;
//					// uploadPath = uploadPath + newfilename;
//					filePath = new File(uploadPath);
//					FileCopyUtils.copy(bytes, filePath);

					Map<String, Object> k = new HashMap<String, Object>();
					k.put("id", course_videos_id);
					k.put("video_photo_src", filePath);
					k.put("video_photo", newfilename);
					String root = req.getSession().getServletContext()
							.getRealPath("");
					// 删除旧的 更新心的
					int effect = iosQuestService.updateVideoPhoto(k, root);
					
//					int effect = iosQuestService.updateTeacherImage(user_id,filePath);
					if (effect == 1) {
						ret.put(ApplicationUtils.STATUS, "1");
						ret.put(ApplicationUtils.MSG, "封面上传成功");
						ret.put("image_src", filePath);
					
					} else {
						ret.put(ApplicationUtils.STATUS, "0");
						ret.put(ApplicationUtils.MSG, "系统异常");
					}
				} else {
					ret.put(ApplicationUtils.STATUS, "0");
					ret.put(ApplicationUtils.MSG, "头像附件过大");
					return ret;
				}
			}
		} catch (Exception se) {
			se.printStackTrace();
		}
		return ret;
	}

	protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("application/json");
		resp.setHeader("Access-Control-Allow-Headers",
				"Content-Range,Content-Type");
		resp.setHeader("Access-Control-Allow-Origin",
				Configurations.getCrossOrigins());
		resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
	}

	@RequestMapping(value = "/downLoadFile")
	public void downLoadFile(HttpServletRequest req, HttpServletResponse resp,
			String token, String fileName) throws ServletException, IOException {
		InputStream in = null;
		fileName = Configurations.getFileRepository() + File.separator
				+ fileName;
		// 1.设置文件ContentType类型，这样设置，会自动判断下载文件类型
		resp.setContentType("multipart/form-data");
		// 2.设置文件头：最后一个参数是设置下载文件名(假如我们叫a.pdf)
		resp.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
		ServletOutputStream out = null;

		try {
			System.out.println("以字节为单位读取文件内容，一次读多个字节：");
			out = resp.getOutputStream();
			// 一次读多个字节
			byte[] tempbytes = new byte[100];
			int byteread = 0;
			in = new FileInputStream(fileName);
			ReadFromFile.showAvailableBytes(in);
			// 读入多个字节到字节数组中，byteread为一次读入的字节数
			while ((byteread = in.read(tempbytes)) != -1) {
				out.write(tempbytes, 0, byteread);
				// System.out.write(tempbytes, 0, byteread);
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
					out.close();
					out.flush();
				} catch (IOException e1) {
				}
			}
		}
	}

	// IOS修改教师资料
	@RequestMapping(value = "/updateTeacher")
	@ResponseBody
	public Object updateTeacher(String token, String name, String address,
			String birthday, String age, String sex, String callback)
			throws Exception {

		HashMap<String,String> m = new HashMap<String,String>();

		if (token == null) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请先登陆");
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}
//		String t_user_id = jedisCache.lindex(token,0);
		String t_user_id = jedisCache.hget(token,com.spera.genutil.TokenUtil.USER_ID);

		if (t_user_id == null) {
//			this.jedisCache.lindex(token,0);
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请先登陆");
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}

		try {
			int effect = iosQuestService.updateTeacher(t_user_id, name,
					address, birthday, age, sex);

			if (effect == 1) {
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "成功修改");
				return m;
			} else {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "修改失败");
			}

		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统报错");
		}

		// System.out.println(m.size());

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	// IOS上传头像
//	@RequestMapping(value = "/updateTeacherImage")
//	@ResponseBody
//	public Object updateTeacherImage(String token, MultipartFile file,
//			String callback, HttpServletRequest request) throws Exception {
//
//		Map<String, Object> m = new HashMap<String, Object>();
//		if (!ApplicationUtils.isNotNull(token)) {
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "请先登录");
//			if (ApplicationUtils.isNotNull(callback))
//				return new JSONPObject(callback, m);
//			else
//				return m;
//		}
//		try {
//			if (!ApplicationUtils.isNotNull(token)) {
//				if (!redisCache.exists(token)) {
//					m.put(ApplicationUtils.STATUS, "0");
//					m.put(ApplicationUtils.MSG, "用户未登录，请先登录");
//					if (ApplicationUtils.isNotNull(callback))
//						return new JSONPObject(callback, m);
//					else
//						return m;
//				}
//			}
//			System.out.println(token + "token");
//			String user_id = redisCache.lindex(token,0);
//
//			if (user_id == null) {
//				m.put(ApplicationUtils.STATUS, "0");
//				m.put(ApplicationUtils.MSG, "用户未登录，请先登录");
//			}
//
//			System.out.println("user_id" + user_id);
//
//			if (!file.isEmpty()) {
//				String fileName = file.getOriginalFilename();
////				Date d = new Date();
////				SimpleDateFormat tempDate = new SimpleDateFormat(
////						"yyyyMMddHHmmss");
//
//				String type = tools.getFileType(fileName);
//
//				// String newfilename = tempDate.format(d)+"."+type;
//				String newfilename = ApplicationUtils.randomUUID() + "." + type;
//
//				Integer fileSize = 0;
//				File filePath = null;
//				byte[] bytes = file.getBytes();
//				fileSize = (int) file.getSize() / 1024;
//				if (fileSize <= 102400) {
//					// String path = request.getRealPath("");
//
//					String uploadStr = "upload" + File.separator + "t_image";
//
//					String uploadPath = request.getSession()
//							.getServletContext().getRealPath(uploadStr);
//
//					String root = request.getSession().getServletContext()
//							.getRealPath("");
//
//					// String uploadPath = "\\upload\\";
//					// String uploadPath = JedisCont.APP_ADDRESS;
//					if (!(new File(uploadPath).isDirectory())) {
//						new File(uploadPath).mkdirs();
//					}
//					uploadPath += File.separator + newfilename;
//
//					int effect = iosQuestService.updateTeacherImage(user_id,
//							File.separator + uploadStr + File.separator
//									+ newfilename, root);
//					// int effect=userDetailService.updateUserImageSrc(user_id,
//					// "/"+uploadStr+"/"+newfilename,root);
//
//					if (effect == 1) {
//						m.put(ApplicationUtils.STATUS, "1");
//						m.put(ApplicationUtils.MSG, "修改成功");
//						m.put("image_src", File.separator + uploadStr
//								+ File.separator + newfilename);
//
//					} else {
//						m.put(ApplicationUtils.STATUS, "0");
//						m.put(ApplicationUtils.MSG, "系统异常");
//					}
//
//					filePath = new File(uploadPath);
//					FileCopyUtils.copy(bytes, filePath);
//
//					System.out.println(uploadPath);
//
//					System.out.println("user_id" + user_id);
//
//					System.out.println("上传成功");
//
//					// user.setImage_src(JedisCont.APP_ADDRESS+newfilename);
//				} else {
//					m.put(ApplicationUtils.STATUS, "0");
//					m.put(ApplicationUtils.MSG, "上传的文件太大，文件大小不能超过10M");
//					return m;
//				}
//			} else {
//				m.put(ApplicationUtils.STATUS, "0");
//				m.put(ApplicationUtils.MSG, "请选择上传的文件");
//			}
//
//		} catch (Exception e) {
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "系统异常");
//			e.printStackTrace();
//		}
//
//		if (ApplicationUtils.isNotNull(callback)) {
//			return new JSONPObject(callback, m);
//		} else {
//			return m;
//		}
//	}
	
	/**
	 * 教师头像上传
	 * @param token
	 * @param file
	 * @param callback
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateTeacherImage")
	@ResponseBody
	public Object updateTeacherImage(String token, MultipartFile file,
			String callback, HttpServletRequest request) throws Exception {

		Map<String, Object> m = checkToken(token);
		if (m != null) {
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}
		try {
			m = new HashMap<String, Object>();
//			String user_id = jedisCache.lindex(token,0);
			String user_id = jedisCache.hget(token,com.spera.genutil.TokenUtil.USER_ID);
			if (!file.isEmpty()) {
				String fileName = file.getOriginalFilename();
				String type = tools.getFileType(fileName);

				String newfilename = "tp_"+ApplicationUtils.randomUUID() + "." + type;

				Integer fileSize = 0;
				fileSize = (int) file.getSize() / 1024;
				if (fileSize <= 102400) {
					String filePath = SperaOSSUtil.springFileUpOss(AliyunContent.fileBucket,"teacher_headimage/"+UDate.getDate()+"/"+newfilename, file);
					
					int effect = iosQuestService.updateTeacherImage(user_id,filePath);
					
					if (effect == 1) {
						m.put(ApplicationUtils.STATUS, "1");
						m.put(ApplicationUtils.MSG, "修改成功");
						m.put("image_src", filePath);

					} else {
						m.put(ApplicationUtils.STATUS, "0");
						m.put(ApplicationUtils.MSG, "系统异常");
					}
				} else {
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "上传的文件太大，文件大小不能超过5M");
					return m;
				}
			} else {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请选择上传的文件");
			}

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	@RequestMapping(value = "/updateTeacherPassword")
	@ResponseBody
	public Object updateTeacherPassword(String token, String old_password,
			String new_password, String callback) throws Exception {

		HashMap<String,String> m = new HashMap<String,String>();

		if (token == null) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请先登陆");
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}

		if (old_password == null) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入旧密码");
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}

		if (new_password == null) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入新密码");
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}

//		String t_user_id = jedisCache.lindex(token,0);
		String t_user_id = jedisCache.hget(token,com.spera.genutil.TokenUtil.USER_ID);
		if (t_user_id == null) {
//			this.jedisCache.lindex(token,0);
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请先登陆");
			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}

		try {
			int effect = iosQuestService.updateTeacherPassword(t_user_id,
					old_password, new_password);

			if (effect == 1) {
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "成功修改");
				if (ApplicationUtils.isNotNull(callback)) {
					return new JSONPObject(callback, m);
				} else {
					return m;
				}
			} else if (effect == -1) {

				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "旧密码错误");

			} else {

				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "修改密码失败");

			}

		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统报错");
		}

		// System.out.println(m.size());

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	private Map<String, Object> checkToken(String token) {
		Map<String, Object> s = new HashMap<String, Object>();
		if (!ApplicationUtils.isNotNull(token)) {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "请先登录");
			return s;
		} else {
			if (!jedisCache.exists(token)) {
				s.put(ApplicationUtils.STATUS, "-9999");
				s.put(ApplicationUtils.MSG, "用户登录已失效，请先重新登录");
				return s;
			} else {
				jedisCache.expire(token, 60 * 60 * 24);
				return null;
			}
		}
	}
	
	//----------------------阿里云OSS  MTS方式的断点续传
	
//	private static final int CONCURRENCIES = 1; //
	// 断点上传获取token
	@RequestMapping(value = "/uploadtk", method = RequestMethod.GET)
	@ResponseBody
	public Object uploadtk(HttpServletRequest req, HttpServletResponse resp,
			String file_name, String file_size) throws ServletException,
			IOException {
		String token = ApplicationUtils.randomUUID();//TokenUtil.generateToken(file_name, file_size);
		Map<String, Object> jsonStr = new HashMap<String, Object>();
		jsonStr.put("token", token);
		int hasin = iosQuestService.checkFileToken(jsonStr);
		if (hasin != 0) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "附件已存在");
			return jsonStr;
		}
		
		if (!ApplicationUtils.isNotNull(file_name)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "附件名不能为空");
			return jsonStr;
		}
		
		if (!ApplicationUtils.isNotNull(file_size)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "未知附件大小");
			return jsonStr;
		}
		
		boolean f = file_name.contains(".");
		if(!f){
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "未知附件类型");
			return jsonStr;
		}
		
		String fileType = file_name.substring(file_name.lastIndexOf(".")+1);
		if(!"mp4".equalsIgnoreCase(fileType)){
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "该附件类型不支持");
			return jsonStr;
		}
		
	    int partCount = SperaOSSUtil.calPartCount(Long.parseLong(file_size));
//	    System.out.println("PART_SIZE------------------->"+AliyunContent.PART_SIZE);
//	    System.out.println("file_size------------------->"+file_size);
//	    System.out.println("partcount------------------->"+partCount);
        if (partCount < 1) {
        	jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "要上传文件的大小必须大于一个Part的字节数：" + AliyunContent.PART_SIZE);
			return jsonStr;
        }
		
		try {
			//第一次上传附件时，将获取到的token存入缓存(后续断点获取不需要写入缓存,只需调用uploadOssPos去获取)
			Query q = new Query(Criteria.where("id").is(token));
			OssPartInfo ossPart= mongoService.findOne(q, OssPartInfo.class);
			if(ossPart==null){
				String filePath = "courseVideo_tmp/"+token+".mp4";
				OSSClient client = CreateOSSClient.getInstance().getOSSClient();//
		    	String uploadId = SperaOSSUtil.initMultipartUpload(client, AliyunContent.inputBucket, filePath);
		    	OssPartInfo tokenObj = new OssPartInfo();
		    	tokenObj.setId(token);
		    	tokenObj.setFileSize(file_size);//文件大小
		    	tokenObj.setUploadId(uploadId);//上传请求id 
		    	tokenObj.setStartPos("0");//起始位置
		    	tokenObj.setStartPart("1");//起始partId
		    	tokenObj.setTotalPart(partCount+"");//附件上传任务总共分为多少片
		    	tokenObj.setFilepath(filePath);
		    	mongoService.insert(tokenObj);
			}
			
			if (Configurations.isCrossed())
				jsonStr.put("server", Configurations.getCrossServer());
			jsonStr.put(ApplicationUtils.STATUS, "1");
			jsonStr.put(ApplicationUtils.MSG, "成功");
		} catch (JSONException e) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "失败");
		}
		System.out.println("TokenServlet---->doGet--->json:" + jsonStr);
		return jsonStr;
	}

	// 断点上传获取pos
//	@SuppressWarnings("null")
	@RequestMapping(value = "/uploadpos", method = RequestMethod.GET)
	@ResponseBody
	public Object uploadpos(HttpServletRequest req, HttpServletResponse resp,
			String token, String file_name, String file_size)
			throws ServletException, IOException {
		Map<String, Object> jsonStr = new HashMap<String, Object>();
		if(ApplicationUtils.isNotNull(token)){
			Query q = new Query(Criteria.where("id").is(token));
			OssPartInfo ossPart= mongoService.findOne(q, OssPartInfo.class);
			if(ossPart!=null){
//			if (redisCache.exists(token)) {
				jsonStr.put("start",ossPart.getStartPos());///*redisCache.lindex(token, 2)*/
				jsonStr.put(ApplicationUtils.STATUS, "1");
				jsonStr.put(ApplicationUtils.MSG, "success");
			}else{
				jsonStr.put("start", null);
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, "false");
			}
		}else{
			jsonStr.put("start", null);
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "false");
		}
		System.out.println("uploadpos---->doGet--->json:" + jsonStr);
		return jsonStr;
	}

	
	
	// 断点上传
	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	@ResponseBody
	public Object upload(HttpServletRequest req, HttpServletResponse resp,
			String token,String file_name,
			@RequestParam(value = "mp4", required = false) MultipartFile mp4,
			String course_open_detail_id, String c_baby_id){
		Map<String, Object> jsonStr = new HashMap<String, Object>();
		try{
			if (!ApplicationUtils.isNotNull(course_open_detail_id)) {
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, "请先选择课程");
				return jsonStr;
			}

			if (!ApplicationUtils.isNotNull(c_baby_id)) {
				c_baby_id = "0";
//				jsonStr.put(ApplicationUtils.STATUS, "0");
//				jsonStr.put(ApplicationUtils.MSG, "请先选择学生");
//				return jsonStr;
			}
			
			if(!ApplicationUtils.isNotNull(token)){
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, "token不能为空");
				return jsonStr;
			}
			
			Query q = new Query(Criteria.where("id").is(token));
			OssPartInfo ossPart= mongoService.findOne(q, OssPartInfo.class);
			if(ossPart==null){
//			if (!redisCache.exists(token)) {
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, "token已失效，请确认附件是否已上传完成");
				return jsonStr;
			}
			
//			if (mp4.getSize()!=AliyunContent.PART_SIZE) {
//				jsonStr.put(ApplicationUtils.STATUS, "0");
//				jsonStr.put(ApplicationUtils.MSG, "单次文件上传大小不符合，");
//				return jsonStr;
//			}

			boolean success = false;
			String this_start = AliyunContent.PART_SIZE*(Integer.parseInt(ossPart.getStartPart()/*redisCache.lindex(token, 3)*/)-1)+"";
			String next_start = "0";
			String message = "success";
			OSSClient client = CreateOSSClient.getInstance().getOSSClient();
			try {
				
				PartETag eTag = SperaOSSUtil.uploadPartByByte(mongoService/*redisCache*/,ossPart.getFilepath(), ossPart.getUploadId()/*redisCache.lindex(token, 1)*/, client,
		        		mp4.getInputStream(),mp4.getSize(),Integer.parseInt(ossPart.getStartPart()/*redisCache.lindex(token, 3)*/));
				if(eTag!=null){
					success = true;
					next_start = (Long.parseLong(this_start)+mp4.getSize())+"";
				}
			} catch (Exception se) {
				jsonStr.put("start", null);
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, message);
//				mongoService.remove(q, OssPartInfo.class);
				
			} finally {
				//附件片段上传成功
				if(success){
					//更新redis
//					redisCache.lset(token, 2, next_start);//下次start
					mongoService.updateFirst(q, Update.update("startPos", next_start), OssPartInfo.class);
					//当前part与总part相比 // 传递完毕
					if (/*redisCache.lindex(token, 3)*/ossPart.getStartPart().equalsIgnoreCase(ossPart.getTotalPart()/*redisCache.lindex(token, 4)*/)) {
						//拼接eTag
						List<PartETag> eTags = new ArrayList<PartETag>();
						Query q_eTags = new Query(Criteria.where("token").is(ossPart.getFilepath()));
						List<SperaPartETag> SperaETags = mongoService.find(q_eTags, SperaPartETag.class);
						for(SperaPartETag se:SperaETags){
							PartETag e = new PartETag(se.getPartNumber(),se.geteTag());
							eTags.add(e);
						}
						SperaOSSUtil.completeMultipartUpload(client,AliyunContent.inputBucket,ossPart.getFilepath(),ossPart.getUploadId()/*redisCache.lindex(token, 1)*/,eTags);
						String course_videos_id = ApplicationUtils.randomUUID();
						Map<String, Object> s = new HashMap<String, Object>();
						s.put("id", course_videos_id);
						s.put("c_baby_ids", c_baby_id);
						s.put("course_open_detail_id", course_open_detail_id);
						s.put("course_videos_id", course_videos_id);
//						s.put("video_src", "/"+ossPart.getFilepath());
						s.put("video_name", file_name);
						s.put("video_token", ossPart.getId());
						iosQuestService.insertVideos(s);
						
						//清除redis
//						redisCache.del(token,token+"-etag");
						mongoService.remove(q_eTags, SperaPartETag.class);
						mongoService.remove(q, OssPartInfo.class);
						
						//MTS转码
						CourseMtsInfo cm = new CourseMtsInfo();
						cm.setTranscodeJobId("0");//待转码
						cm.setModelName("coursevideo");
						cm.setCourseVideosId(course_videos_id);
						cm.setOssFilePath(ossPart.getFilepath());
						cm.setBabyIDs(c_baby_id);
						mongoService.insert(cm);
						
						jsonStr.put("course_videos_id", course_videos_id);
						
					}else{
						//更新
//					redisCache.lset(token, 3, (Integer.parseInt(redisCache.lindex(token, 3))+1)+"");//下次part
						mongoService.updateFirst(q, Update.update("startPart", (Integer.parseInt(ossPart.getStartPart())+1)+""), OssPartInfo.class);
					}
					
					jsonStr.put("start", next_start);
					jsonStr.put(ApplicationUtils.STATUS, "1");
					jsonStr.put(ApplicationUtils.MSG, message);
					System.out.println("upload---->dopost--->json:" + jsonStr);
				}else{
					jsonStr.put("start", null);
					jsonStr.put(ApplicationUtils.STATUS, "0");
					jsonStr.put(ApplicationUtils.MSG, "第"+ossPart.getStartPart()/*redisCache.lindex(token, 3)*/+"部分上传失败");
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return jsonStr;
	}
	
	/**
	 * 教师对孩子评论
	 * @param token
	 * @param commet
	 * @param course_open_detail_id
	 * @param c_family_member_id
	 * @param baby_name
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/teacherCommentBabyOld")
	@ResponseBody
	public Object teacherCommentBaby(String token,String commet,
			String course_open_detail_id,String c_family_member_id,String baby_name,String teacher_name, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = iosQuestService.teacherCommentBaby(token, commet, course_open_detail_id, c_family_member_id, baby_name,teacher_name);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	

	@RequestMapping(value = "/teacherCommentBaby")
	@ResponseBody
	public Object teacherCommentBabynew(String token,String comment,
			String course_open_detail_id,String c_family_member_id,String c_user_id,String baby_name,String teacher_name, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		Map<String, Object> t = com.spera.genutil.TokenUtil.checkToken(token, jedisCache);
		if (t != null) {

			return t;

		}
//		String c_user_id = jedisCache.lindex(token, 0);
//		String user_name = jedisCache.lindex(token, 1);
		
		String t_user_id = jedisCache.hget(token, com.spera.genutil.TokenUtil.USER_ID);
		String user_name = jedisCache.hget(token, com.spera.genutil.TokenUtil.USER_NAME);
		
		if(c_user_id==null||c_user_id.equals("")){
			c_user_id=c_family_member_id;
			
		}
		
		try {
			//insertCommentCustomerService
			m = commentService.insertCommentCustomerService(c_user_id, "3", baby_name, t_user_id, "2",
					user_name, course_open_detail_id, "1002", "3", comment);
			
		//	m = commentService.insertCommentCustomerService(toUserID, toUserType, toUserName, fromUserID, fromUserType, fromUserName, serviceID, businessTypeCode, serviceModuleCode, comment)
			//m = iosQuestService.teacherCommentBaby(token, commet, course_open_detail_id, c_family_member_id, baby_name,teacher_name);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	
	/**
	 * 教师对课堂评论
	 * @param token
	 * @param commet
	 * @param course_open_detail_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/teacherCommentCourseOld")
	@ResponseBody
	public Object teacherCommentCourse(String token,String commet,
			String course_open_detail_id,String teacher_name ,String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = iosQuestService.teacherCommentCourse(token, commet, course_open_detail_id,teacher_name);
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	//教师对课堂评论new
	@RequestMapping(value = "/teacherCommentCourse")
	@ResponseBody
	public Object teacherCommentCourseNew(String token,String comment,
			String course_open_detail_id,String teacher_name ,String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		
		Map<String, Object> t = com.spera.genutil.TokenUtil.checkToken(token, jedisCache);
		if (t != null) {

			return t;

		}
//		String c_user_id = jedisCache.lindex(token, 0);
//		String user_name = jedisCache.lindex(token, 1);
		
		String c_user_id = jedisCache.hget(token, com.spera.genutil.TokenUtil.USER_ID);
		String user_name = jedisCache.hget(token, com.spera.genutil.TokenUtil.USER_NAME);
		
		try {

			m = commentService.insertCommentService(c_user_id, "2", user_name, course_open_detail_id, "1002", "1", comment);
			//m = iosQuestService.teacherCommentCourse(token, commet, course_open_detail_id,teacher_name);
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	
	/**
	 * 查看教师对孩子评论
	 * @param token
	 * @param commet
	 * @param course_open_detail_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getTeacherCommentBabyListOld")
	@ResponseBody
	public Object getTeacherCommentBabyList(String token,String course_open_detail_id,String c_user_id,String page_size,
			String page_index,String skip,String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			
			m = iosQuestService.getTeacherCommentBabyList(token, course_open_detail_id, c_user_id,page_size, page_index, skip, rows);
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	
	/**
	 * 查看教师对孩子评论
	 * @param token
	 * @param commet
	 * @param course_open_detail_id
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getTeacherCommentBabyList")
	@ResponseBody
	public Object getTeacherCommentBabyListNew(String token,String course_open_detail_id,String c_user_id,String page_size,
			String page_index,String skip,String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			
			m = iosQuestService.getTeacherCommentBabyListNew(token, course_open_detail_id, c_user_id,page_size, page_index, skip, rows);
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}	
	
	
	
	
	/**
	 * 查看教师对课程的评论
	 * @param token
	 * @param course_open_detail_id
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getTeacherCommentCourseListOld")
	@ResponseBody
	public Object getTeacherCommentCourseList(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = iosQuestService.getTeacherCommentCourseList(token, course_open_detail_id, page_size, page_index, skip, rows);
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	/**
	 * 查看教师对课程的评论
	 * @param token
	 * @param course_open_detail_id
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getTeacherCommentCourseList")
	@ResponseBody
	public Object getTeacherCommentCourseListNew(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = iosQuestService.getTeacherCommentCourseListNew(token, course_open_detail_id, page_size, page_index, skip, rows);
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/**
	 * 查看教师对课程的评论
	 * @param token
	 * @param course_open_detail_id
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getParentCommentCourseListOld")
	@ResponseBody
	public Object getParentCommentCourseList(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			m = iosQuestService.getParentCommentCourseList(token, course_open_detail_id, page_size, page_index, skip, rows);
					
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	/**
	 * 查看教师对课程的评论
	 * @param token
	 * @param course_open_detail_id
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getParentCommentCourseList")
	@ResponseBody
	public Object getParentCommentCourseListNew(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows, String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {

			//m = iosQuestService.getParentCommentCourseList(token, course_open_detail_id, page_size, page_index, skip, rows);
			m = iosQuestService.getParentCommentCourseListNew(token, course_open_detail_id, page_size, page_index, skip, rows)	;
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	/**
	 * 图片断点上传获取token
	 * @param req
	 * @param resp
	 * @param file_name
	 * @param file_size
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping(value = "/uploadImageTk", method = RequestMethod.GET)
	@ResponseBody
	public Object uploadImageTk(HttpServletRequest req, HttpServletResponse resp,
			String file_name, String file_size) throws ServletException,
			IOException {
		String token = TokenUtil.generateToken(file_name, file_size);
		Map<String, Object> jsonStr = new HashMap<String, Object>();
		int hasin = iosQuestService.checkImageFileToken(jsonStr);
		if (hasin != 0) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "附件已存在");
			return jsonStr;
		}
		
		if (!ApplicationUtils.isNotNull(file_name)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "附件名不能为空");
			return jsonStr;
		}
		
		if (!ApplicationUtils.isNotNull(file_size)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "未知附件大小");
			return jsonStr;
		}
		
		boolean f = file_name.contains(".");
		if(!f){
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "未知附件类型");
			return jsonStr;
		}
		
		String fileType = file_name.substring(file_name.lastIndexOf(".")+1);
		if(!"jpg".equalsIgnoreCase(fileType)&&!"jpeg".equalsIgnoreCase(fileType)&&
				!"png".equalsIgnoreCase(fileType)&&!"bmp".equalsIgnoreCase(fileType)){
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "该附件类型不支持");
			return jsonStr;
		}
		jsonStr.put("token", token);
	    int partCount = SperaOSSUtil.calPartCount(Long.parseLong(file_size));
        if (partCount < 1) {
        	partCount=1;
//        	jsonStr.put(ApplicationUtils.STATUS, "1");
//			jsonStr.put(ApplicationUtils.MSG, "要上传文件的大小必须大于一个Part的字节数：" + AliyunContent.PART_SIZE);
//			return jsonStr;
        }
		
		try {
			//第一次上传附件时，将获取到的token存入缓存(后续断点获取不需要写入缓存,只需调用uploadOssPos去获取)
			Query q = new Query(Criteria.where("id").is(token));
			OssPartInfo ossPart= mongoService.findOne(q, OssPartInfo.class);
			if(ossPart==null){

			//	String filePath = "courseImage/"+UDate.getDate()+"/"+token+".jpg"/*+file_name.substring(file_name.lastIndexOf("."))*/;

				String filePath = "courseImage/"+UDate.getDate()+"/"+token+"."+fileType/*+file_name.substring(file_name.lastIndexOf("."))*/;

				OSSClient client = CreateOSSClient.getInstance().getOSSClient();//
		    	String uploadId = SperaOSSUtil.initMultipartUpload(client, AliyunContent.inputBucket, filePath);
		    	OssPartInfo tokenObj = new OssPartInfo();
		    	tokenObj.setId(token);
		    	tokenObj.setFileSize(file_size);//文件大小
		    	tokenObj.setUploadId(uploadId);//上传请求id 
		    	tokenObj.setStartPos("0");//起始位置
		    	tokenObj.setStartPart("1");//起始partId
		    	tokenObj.setTotalPart(partCount+"");//附件上传任务总共分为多少片
		    	tokenObj.setFilepath(filePath);
		    	mongoService.insert(tokenObj);
			}
			if (Configurations.isCrossed())
				jsonStr.put("server", Configurations.getCrossServer());
			jsonStr.put(ApplicationUtils.STATUS, "1");
			jsonStr.put(ApplicationUtils.MSG, "成功");
		} catch (JSONException e) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "失败");
		}
		System.out.println("TokenServlet---->doGet--->json:" + jsonStr);
		return jsonStr;
	}

	// 图片断点上传获取pos
	@RequestMapping(value = "/uploadImagePos", method = RequestMethod.GET)
	@ResponseBody
	public Object uploadImagePos(HttpServletRequest req, HttpServletResponse resp,
			String token, String file_name, String file_size)
			throws ServletException, IOException {
		Map<String, Object> jsonStr = new HashMap<String, Object>();
		if(ApplicationUtils.isNotNull(token)){
			Query q = new Query(Criteria.where("id").is(token));
			OssPartInfo ossPart= mongoService.findOne(q, OssPartInfo.class);
			if(ossPart!=null){
//			if (redisCache.exists(token)) {
				jsonStr.put("start",ossPart.getStartPos());///*redisCache.lindex(token, 2)*/
				jsonStr.put(ApplicationUtils.STATUS, "1");
				jsonStr.put(ApplicationUtils.MSG, "success");
			}else{
				jsonStr.put("start", null);
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, "false");
			}
		}else{
			jsonStr.put("start", null);
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "false");
		}
		System.out.println("uploadpos---->doGet--->json:" + jsonStr);
		return jsonStr;
	}

	// 图片断点上传
	@RequestMapping(value = "/uploadImage", method = RequestMethod.POST)
	@ResponseBody
	public Object uploadImage(HttpServletRequest req, HttpServletResponse resp,
			String token,String file_name,
			@RequestParam(value = "image", required = true) MultipartFile image,
			String course_open_detail_id, String c_baby_id)
			throws ServletException, IOException {
		Map<String, Object> jsonStr = new HashMap<String, Object>();

		if (!ApplicationUtils.isNotNull(course_open_detail_id)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "请先选择课程");
			return jsonStr;
		}

		if (!ApplicationUtils.isNotNull(c_baby_id)) {
			c_baby_id = "0";
//			jsonStr.put(ApplicationUtils.STATUS, "0");
//			jsonStr.put(ApplicationUtils.MSG, "请先选择学生");
//			return jsonStr;
		}
		
		if(!ApplicationUtils.isNotNull(token)){
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "token不能为空");
			return jsonStr;
		}
		
		Query q = new Query(Criteria.where("id").is(token));
		OssPartInfo ossPart= mongoService.findOne(q, OssPartInfo.class);
		if(ossPart==null){
//		if (!redisCache.exists(token)) {
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, "token已失效，请确认附件是否已上传完成");
			return jsonStr;
		}

		boolean success = false;
		//PartETag eTag=null;
		String this_start = AliyunContent.PART_SIZE*(Integer.parseInt(ossPart.getStartPart()/*redisCache.lindex(token, 3)*/)-1)+"";
		String next_start = "0";
		String message = "success";
		OSSClient client = CreateOSSClient.getInstance().getOSSClient();
		try {
			//上传
			PartETag eTag = SperaOSSUtil.uploadPartByByte(mongoService/*redisCache*/,ossPart.getFilepath(), ossPart.getUploadId()/*redisCache.lindex(token, 1)*/, client,
					image.getInputStream(),image.getSize(),Integer.parseInt(ossPart.getStartPart()/*redisCache.lindex(token, 3)*/));
			if(eTag!=null){
				success = true;
				next_start = (Long.parseLong(this_start)+image.getSize())+"";
			}
		} catch (Exception se) {
			jsonStr.put("start", null);
			jsonStr.put(ApplicationUtils.STATUS, "0");
			jsonStr.put(ApplicationUtils.MSG, message);
			
		} finally {
			//附件片段上传成功
			if(success){
				//更新redis
				mongoService.updateFirst(q, Update.update("startPos", next_start), OssPartInfo.class);
				//当前part与总part相比 // 传递完毕
				if (/*redisCache.lindex(token, 3)*/ossPart.getStartPart().equalsIgnoreCase(ossPart.getTotalPart()/*redisCache.lindex(token, 4)*/)) {
					//拼接eTag
					List<PartETag> eTags = new ArrayList<PartETag>();
					Query q_eTags = new Query(Criteria.where("token").is(ossPart.getFilepath()));
					List<SperaPartETag> SperaETags = mongoService.find(q_eTags, SperaPartETag.class);
					for(SperaPartETag se:SperaETags){
						PartETag e = new PartETag(se.getPartNumber(),se.geteTag());
						eTags.add(e);
					}
					SperaOSSUtil.completeMultipartUpload(client,AliyunContent.inputBucket,ossPart.getFilepath(),
							ossPart.getUploadId()/*redisCache.lindex(token, 1)*/,eTags);
					String course_images_id = ApplicationUtils.randomUUID();
					Map<String, Object> s = new HashMap<String, Object>();
					s.put("id", course_images_id);
					s.put("c_baby_ids", c_baby_id);
					s.put("course_open_detail_id", course_open_detail_id);
					s.put("course_images_id", course_images_id);
					String image_src = "http://" + AliyunContent.inputBucket + ".img-cn-hangzhou.aliyuncs.com/" + ossPart.getFilepath();
						
					iosQuestService.createIOSPhotoJournal(image_src, ossPart.getFilepath(), c_baby_id);
					
					
					s.put("image_src", image_src);
					s.put("image_name", file_name);
					s.put("image_token", token);
					iosQuestService.insertCourseImages(s);
					//清除mongodb
					mongoService.remove(q_eTags, SperaPartETag.class);
					mongoService.remove(q, OssPartInfo.class);
					jsonStr.put("course_images_id", course_images_id);
				}else{
					mongoService.updateFirst(q, Update.update("startPart", (Integer.parseInt(ossPart.getStartPart())+1)+""), OssPartInfo.class);
				}
				
				jsonStr.put("start", next_start);
				jsonStr.put(ApplicationUtils.STATUS, "1");
				jsonStr.put(ApplicationUtils.MSG, message);
				System.out.println("upload---->dopost--->json:" + jsonStr);
			}else{
				jsonStr.put("start", null);
				jsonStr.put(ApplicationUtils.STATUS, "0");
				jsonStr.put(ApplicationUtils.MSG, "第"+ossPart.getStartPart()/*redisCache.lindex(token, 3)*/+"部分上传失败");
			}
		}
		return jsonStr;
	}
}
